package com.example.springboot.Dao;

import com.example.springboot.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.nio.file.OpenOption;

@Repository
public class UserRedisDao {

    @Autowired
    StringRedisTemplate stringRedisTemplate;//springboot已为我们自动配置了StringRedisTemplate，在此处可以直接注入
    @Resource(name = "stringRedisTemplate")
    ValueOperations<String,String> operationsStr;
    @Autowired
    RedisTemplate<Object,Object> redisTemplate;//springboot已为我们自动配置了RedisTemplate，在此处可以直接注入
    @Resource(name = "redisTemplate")
    ValueOperations<Object,Object> valueOperations;

    public void save(User user){
        valueOperations.set("xx",user);
    }

    public User getUser(User user){
       User user1 =  (User) valueOperations.get("xx");
        System.out.println(user1.toString());
        return user1;
    }

    public void deletUser(){
        redisTemplate.delete("xx");
    }
}
